import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wu_you/data/repository/home_repository.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/model/home/home_model.dart';
import 'package:wu_you/page/message/page_notice.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/state/bloc/home_bloc.dart';
import 'package:wu_you/state/bloc/http_bloc.dart';
import 'package:wu_you/utils/navigator_util.dart';
import 'package:wu_you/utils/utils.dart';
import 'package:wu_you/widgets/http_list_widget.dart';
import 'package:wu_you/widgets/update_version_view.dart';
import 'package:package_info/package_info.dart';
import 'package:toast/toast.dart';

class VersionPage extends StatefulWidget {
  @override
  _VersionPageState createState() => _VersionPageState();
}

class _VersionPageState extends State<VersionPage> {
  String _version = '';
  String _appName = '无忧购';

  @override
  void initState() {
    super.initState();
  }

  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        title: Text("${message['versionInfo']}"),
      ),
      body: HttpListWidget<NoticeModel, PlatformNoticeBloc>(
        creator: (context) => PlatformNoticeBloc(),
        onObtainData: (context, page) {
          BlocProvider.of<PlatformNoticeBloc>(context).add(PageSizeHttpEvent(page, 10));
        },
        successBuilder: (context, data) {
          return ListView.separated(
            separatorBuilder: (context, index) {
              return Divider(height: 1);
            },
            itemCount: data.length,
            itemBuilder: (context, index) {
              var item = data[index];
              return ListTile(
                tileColor: Colors.white,
                title: Text(
                  item.title,
                  style: TextStyle(fontSize: 16, color: AppColors.textColor),
                ),
                trailing:
                Icon(
                  Icons.arrow_forward_ios_rounded,
                  size: 14,
                ),
                subtitle: Padding(
                  padding: EdgeInsets.only(top: 8),
                  child: Text(
                    item.time,
                    style: TextStyle(fontSize: 14, color: AppColors.textHintColor),
                  ),
                ),
                onTap: () {
                  NavigatorUtil.navigateToPage(context, NoticeDetailPage(item.title, item.content));
                },
              );
            },
          );
        },
      ),
    );
  }


}
